package com.cloud.cop.response;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import com.cloud.cop.validation.MainError;
import com.cloud.cop.validation.MainErrorType;
import com.cloud.cop.validation.MainErrors;
import com.cloud.cop.validation.SubError;
import com.cloud.cop.validation.SubErrors;


/**
 * <pre>
 * 		当服务器发生错误的时候
 * </pre>
 * @author mayh
 *
 */

public class ServiceErrorResponse extends ErrorCopResponse {
	
	private static final String ISV = "isv.";
	private static final String SERVICE_ERROR = "-service-error:";
	
	/**
	 * 
	 */
	public ServiceErrorResponse(String serviceName,String errorCode,Locale locale,Object... params){
		MainError mainError = MainErrors.getErrors(MainErrorType.SAVE_FAIL, locale);
		serviceName = transform(serviceName);
		String subErrorCode = ISV+serviceName+SERVICE_ERROR+errorCode;
		SubError subError = SubErrors.getSubError(subErrorCode, subErrorCode, locale, params);
		List<SubError> subErrors = new ArrayList<SubError>();
		subErrors.add(subError);
		setMainError(mainError);
		setSubErrors(subErrors);
	}
	
	public String transform(String serviceName){
		return serviceName = serviceName.replace(".","-");
	}
	
}
